import React from 'react';
import { toJS } from 'mobx'
import { ListViewPage } from 'weaver-mobile-page';
import { openHrmCard } from '../../util'

//操作日志
const WrOperateLog = ({ showCheck = true, logStore, handleRefresh, handleEndReached ,heightSpace=0,customHeight}) => {
    return (
        <ListViewPage.Normal
            getDataCustom={true}
            store={logStore}
            getTemplate={() => buildLogTemplate()}
            onRefresh={() => handleRefresh()}
            onEndReached={() => handleEndReached()}
            customHeight={customHeight}
            heightSpace={heightSpace}
        />
    )
}
//操作日志构建模板
const buildLogTemplate = (template) => {
    const prefixClass = 'workrelate-mobile-log-';
    return {
        default: [{
            key: 'id',
            render: (data) => (
                <div className={`${prefixClass}container`}>
                    <div className={`${prefixClass}log-view`}>
                        <div className={`${prefixClass}name-date`}>
                            <span className={`${prefixClass}name`}>
                                {
                                    data.operatoragentname&&<span>
                                        <a href="javaScript:void(0)" onClick={(e) => openHrmCard(data.operatoragent, e)}>
                                    {data.operatoragentname}
                                </a>
                                <span>-></span>
                                    </span>
                                }
                                <a href="javaScript:void(0)" onClick={(e) => openHrmCard(data.operator, e)}>
                                    {data.operatorname}
                                </a>
                            </span>
                            <span className={`${prefixClass}date`}>
                                {data.operatedate}
                            </span>
                        </div>
                        <div className={`${prefixClass}operatetype`}>
                            {data.operatetitle && <span>{data.operatetitle}&nbsp;</span>}
                            {data.operatetype || data.operatevalue}
                            {
                                data.rlist &&
                                data.rlist.map((d, i) => {
                                    return <div className={`${prefixClass}operatelink`} onClick={() => { window.openAppLink(null, d.id, getFromLinkType(data.linktype), null, null) }}>{d.name}</div>
                                })
                            }
                        </div>
                    </div>
                </div>
            )
        }]
    }
}

// 转换链接类型
const getFromLinkType = (linktype) => {
    if (linktype == "1") {
        return 1
    } else if (linktype == "2" || linktype == "7") {
        return 37
    } else if (linktype == "3") {
        return 152
    } else if (linktype == "4") {
        return 7
    } else if (linktype == "5") {
        return 8
    } else if (linktype == "6") {
        return "wrltask"
    } else if (linktype == "8") {
        return "wrlgoal"
    }
}

export default WrOperateLog;